package com.yootk;
import java.util.concurrent.*;
public class YootkDemo09 {
    public static void main(String[] args) throws  Exception {
        BlockingQueue<String> blockingQueue = new ArrayBlockingQueue<String>(5);
        for (int x = 0; x < 10; x++) {
            final int temp = x;
            new Thread(() -> {
                for (int y = 0; y < 100; y++){
                    try{
                        TimeUnit.SECONDS.sleep(2);
                        String msg = "{ID = MUYAN - " + temp +" - " + y +"}慕言科技：www.yootk.com";
                        blockingQueue.put(msg);
                        System.out.println("【" + Thread.currentThread().getName()+ "】" + msg);
                    }catch (Exception e){}
                }
            }, "YOOTK生产者-" + x).start();
        }
        for (int x = 0; x < 5; x++) {
            new Thread(() -> {
                while (true){
                    try{
                        TimeUnit.SECONDS.sleep(1);
                        System.out.println("【" + Thread.currentThread().getName()+ "】" + blockingQueue.take());
                    }catch (InterruptedException e){}
                }
            }, "YOOTK消费者-" + x).start();
        }
    }
}
